<?php
//------------------------------------------------------------ Contraintes d'accès de la page

	// on vérifie que cette page est appelée à partir de l'index et que l'utilisateur a le droit de consultation
	if(isset($_SESSION) && ($GLOBALS['USER']['level'] >= 2 || $GLOBALS['USER']['admin'])){
	
		// l'identifiant de la donnée à supprimer est indiqué par un entier
		if(isset($_GET['id']) && numericInt($_GET['id'])){
		
			$nb_touffes = valueExists((int)$_GET['id'], "CODETOUFFE", "touffe", $connexion);
			
			if($nb_touffes == 1){ // le sachet de graines à afficher existe et son identifiant est unique
	
?>
<?php
/********************************* Règles :

	- id doit désigner une seule touffe
	- La touffe doit exister dans la BDD

*****************************************/

	$touffe = array(); // on créé un tableau contenant toutes les informations du semis

	// récupération des informations de la touffe
	$query_recuperation_touffe = "SELECT tou.QUANTITEPIEDS AS quantite, tou.REFERENCETOUFFE AS reference, tou.DATEPLANTATION AS plantation, tou.DATEDERNIEREFOISVU AS vue, par.NOMPARCELLE AS parcelle, tc.NOMTYPECULTURE AS culture, eu.NOMETATUSURE AS etiquette, t.CODETAXON AS idTaxon, f.NOMFAMILLE AS famille, g.NOMGENRE AS genre, e.NOMESPECE AS espece, sesp.NOMSOUSESPECE AS sousespece, v.NOMVARIETE AS variete, tou.COMMENTAIRE AS commentaire ";
	$query_recuperation_touffe .= "FROM touffe tou ";
	$query_recuperation_touffe .= "LEFT JOIN parcelle par ON par.CODEPARCELLE = tou.CODEPARCELLE ";
	$query_recuperation_touffe .= "LEFT JOIN type_culture tc ON tc.CODETYPECULTURE = tou.CODETYPECULTURE ";
	$query_recuperation_touffe .= "LEFT JOIN etat_usure eu ON eu.CODEETATUSURE = tou.CODEETATUSURE ";
	$query_recuperation_touffe .= "INNER JOIN taxon t ON t.CODETAXON = tou.CODETAXON ";
	$query_recuperation_touffe .= "LEFT JOIN est_de_famille l1 INNER JOIN famille f ON f.CODEFAMILLE = l1.CODEFAMILLE ON l1.CODETAXON = t.CODETAXON AND l1.CODECLASSIFICATION = t.CODECLASSIFICATION ";
	$query_recuperation_touffe .= "LEFT JOIN appartient_a_genre l2 INNER JOIN genre g ON g.CODEGENRE = l2.CODEGENRE ON l2.CODETAXON = t.CODETAXON AND l2.CODECLASSIFICATION = t.CODECLASSIFICATION ";
	$query_recuperation_touffe .= "LEFT JOIN est_de_espece l3 INNER JOIN espece e ON e.CODEESPECE = l3.CODEESPECE ON l3.CODETAXON = t.CODETAXON AND l3.CODECLASSIFICATION = t.CODECLASSIFICATION ";
	$query_recuperation_touffe .= "LEFT JOIN est_de_sous_espece l33 INNER JOIN sous_espece sesp ON sesp.CODESOUSESPECE = l33.CODESOUSESPECE ON l33.CODETAXON = t.CODETAXON AND l33.CODECLASSIFICATION = t.CODECLASSIFICATION ";
	$query_recuperation_touffe .= "LEFT JOIN a_comme_variete l4 INNER JOIN variete v ON v.CODEVARIETE = l4.CODEVARIETE ON l4.CODETAXON = t.CODETAXON AND l4.CODECLASSIFICATION = t.CODECLASSIFICATION ";
	$query_recuperation_touffe .= "WHERE tou.CODETOUFFE = ".$_GET['id']." ";
	
	$result_recuperation_touffe = mysql_query($query_recuperation_touffe, $connexion) or logError("RECUPERATION SEMIS-".$query_recuperation_touffe."-".mysql_error());

	while($tab_recuperation_touffe = mysql_fetch_assoc($result_recuperation_touffe)){
		
		$touffe['quantite'] = $tab_recuperation_touffe['quantite'];
		$touffe['vue'] = $tab_recuperation_touffe['vue'];
		$touffe['parcelle'] = $tab_recuperation_touffe['parcelle'];
		$touffe['etiquette'] = $tab_recuperation_touffe['etiquette'];
		$touffe['culture'] = $tab_recuperation_touffe['culture'];
		$touffe['reference'] = $tab_recuperation_touffe['reference'];
		$touffe['plantation'] = $tab_recuperation_touffe['plantation'];
		$touffe['taxon']['id'] = $tab_recuperation_touffe['idTaxon'];
		$touffe['taxon']['famille'] = $tab_recuperation_touffe['famille'];
		$touffe['taxon']['genre'] = $tab_recuperation_touffe['genre'];
		$touffe['taxon']['espece'] = $tab_recuperation_touffe['espece'];
		$touffe['taxon']['sousespece'] = $tab_recuperation_touffe['sousespece'];
		$touffe['taxon']['variete'] = $tab_recuperation_touffe['variete'];
		$touffe['commentaire'] = $tab_recuperation_touffe['commentaire'];
	
	}
	
	mysql_free_result($result_recuperation_touffe);
	
	// récupération des entrées de la touffe
	$query_recuperation_entrees = "SELECT en.CODEENTREE AS idEntree, en.DATEENTREE AS dateEntree, en.NUMENTREE AS numEntree, en.NUMIPEN AS ipen, vn.CODEVISITEDANSNATURE AS idVisite, vn.DATEVISITE AS dateVisite, co.NOMCOMMUNE AS communeVisite, co.CODEPOSTAL AS cpVisite, ed.NOMTYPEENTREEDIVERSE AS entreeDiverse, se.CODESEMIS AS idSemis, se.REFERENCESEMIS AS refSemis, pee.CODEPERSONNE AS idPersonneEntree, pee.NOMPERSONNE AS nomPersonneEntree, pee.PRENOMPERSONNE AS prenomPersonneEntree, cmi.CODECOMMANDEINTERNE AS idCommandeEntree, cmi.DATECOMMANDE AS dateCommandeEntree, stcmi.NOMSTRUCTURE AS structureCommandeEntree, pre.CODEPRETENTRANT AS idPretEntree, stpre.NOMSTRUCTURE AS structurePretEntree, retprs.CODEPRETSORTANT AS idPretRetourSortie, stretprs.NOMSTRUCTURE AS structurePretRetourSortie, ste.CODESTRUCTURE AS idStructureEntree, ste.NOMSTRUCTURE AS structureEntree ";
	$query_recuperation_entrees .= "FROM entree en ";
	$query_recuperation_entrees .= "LEFT JOIN visite_dans_nature vn ON vn.CODEVISITEDANSNATURE = en.CODEVISITEDANSNATURE ";
	$query_recuperation_entrees .= "LEFT JOIN commune co ON co.CODECOMMUNE = vn.CODECOMMUNE ";
	$query_recuperation_entrees .= "LEFT JOIN type_entree_diverse ed ON ed.CODETYPEENTREEDIVERSE = en.CODETYPEENTREEDIVERSE ";
	$query_recuperation_entrees .= "LEFT JOIN semis se ON se.CODESEMIS = en.CODESEMIS ";
	$query_recuperation_entrees .= "LEFT JOIN personne pee ON pee.CODEPERSONNE = en.CODEPERSONNE ";
	$query_recuperation_entrees .= "LEFT JOIN ligne_livraison ll ON ll.CODELIGNELIVRAISON = en.CODELIGNELIVRAISON ";
	$query_recuperation_entrees .= "LEFT JOIN livraison lv ON lv.CODELIVRAISON = ll.CODELIVRAISON ";
	$query_recuperation_entrees .= "LEFT JOIN commande_interne cmi ON cmi.CODECOMMANDEINTERNE = lv.CODECOMMANDEINTERNE ";
	$query_recuperation_entrees .= "LEFT JOIN structure stcmi ON stcmi.CODESTRUCTURE = cmi.CODESTRUCTURE ";
	$query_recuperation_entrees .= "LEFT JOIN pret_entrant pre ON pre.CODEPRETENTRANT = en.CODEPRETENTRANT ";
	$query_recuperation_entrees .= "LEFT JOIN structure stpre ON stpre.CODESTRUCTURE = pre.CODESTRUCTURE ";
	$query_recuperation_entrees .= "LEFT JOIN pret_sortant retprs ON retprs.CODEPRETSORTANT = en.CODEPRETSORTANT ";
	$query_recuperation_entrees .= "LEFT JOIN structure stretprs ON retprs.CODESTRUCTURE = stretprs.CODESTRUCTURE ";
	$query_recuperation_entrees .= "LEFT JOIN structure ste ON ste.CODESTRUCTURE = en.CODESTRUCTURE ";
	$query_recuperation_entrees .= "WHERE en.TOU_CODETOUFFE = ".$_GET['id']." ";
	$query_recuperation_entrees .= "ORDER BY dateEntree DESC ";
	
	$result_recuperation_entrees = mysql_query($query_recuperation_entrees, $connexion) or logError("RECUPERATION SEMIS-".$query_recuperation_entrees."-".mysql_error());
	
	$touffe['ipen'] = null;
	while($tab_recuperation_entrees = mysql_fetch_assoc($result_recuperation_entrees)){
		
		if(!is_null($tab_recuperation_entrees['ipen'])){
			$touffe['ipen'] = $tab_recuperation_entrees['ipen'];
		}
		
		$touffe['entrees'][$tab_recuperation_entrees['idEntree']]['date'] = $tab_recuperation_entrees['dateEntree'];
		$touffe['entrees'][$tab_recuperation_entrees['idEntree']]['numero'] = $tab_recuperation_entrees['numEntree'];
	
		if(!is_null($tab_recuperation_entrees['idVisite'])){
			$touffe['entrees'][$tab_recuperation_entrees['idEntree']]['visite']['id'] = $tab_recuperation_entrees['idVisite'];
			$touffe['entrees'][$tab_recuperation_entrees['idEntree']]['visite']['date'] = $tab_recuperation_entrees['dateVisite'];
			$touffe['entrees'][$tab_recuperation_entrees['idEntree']]['visite']['commune'] = $tab_recuperation_entrees['communeVisite'];
		}
		if(!is_null($tab_recuperation_entrees['entreeDiverse'])){
			$touffe['entrees'][$tab_recuperation_entrees['idEntree']]['divers'] = $tab_recuperation_entrees['entreeDiverse'];
		}
		if(!is_null($tab_recuperation_entrees['idSemis'])){
			$touffe['entrees'][$tab_recuperation_entrees['idEntree']]['semis']['id'] = $tab_recuperation_entrees['idSemis'];
			$touffe['entrees'][$tab_recuperation_entrees['idEntree']]['semis']['reference'] = $tab_recuperation_entrees['refSemis'];
		}
		if(!is_null($tab_recuperation_entrees['idPersonneEntree'])){
			$touffe['entrees'][$tab_recuperation_entrees['idEntree']]['personne']['id'] = $tab_recuperation_entrees['idPersonneEntree'];
			$touffe['entrees'][$tab_recuperation_entrees['idEntree']]['personne']['nom'] = $tab_recuperation_entrees['nomPersonneEntree'];
			$touffe['entrees'][$tab_recuperation_entrees['idEntree']]['personne']['prenom'] = $tab_recuperation_entrees['prenomPersonneEntree'];
		}
		if(!is_null($tab_recuperation_entrees['idCommandeEntree'])){
			$touffe['entrees'][$tab_recuperation_entrees['idEntree']]['commande']['id'] = $tab_recuperation_entrees['idCommandeEntree'];
			$touffe['entrees'][$tab_recuperation_entrees['idEntree']]['commande']['date'] = $tab_recuperation_entrees['dateCommandeEntree'];
			$touffe['entrees'][$tab_recuperation_entrees['idEntree']]['commande']['structure'] = $tab_recuperation_entrees['structureCommandeEntree'];
		}
		if(!is_null($tab_recuperation_entrees['idPretEntree'])){
			$touffe['entrees'][$tab_recuperation_entrees['idEntree']]['pret']['id'] = $tab_recuperation_entrees['idPretEntree'];
			$touffe['entrees'][$tab_recuperation_entrees['idEntree']]['pret']['structure'] = $tab_recuperation_entrees['structurePretEntree'];
		}
		if(!is_null($tab_recuperation_entrees['idPretRetourSortie'])){
			$touffe['entrees'][$tab_recuperation_entrees['idEntree']]['retour']['id'] = $tab_recuperation_entrees['idPretRetourSortie'];
			$touffe['entrees'][$tab_recuperation_entrees['idEntree']]['retour']['structure'] = $tab_recuperation_entrees['structurePretRetourSortie'];
		}
		if(!is_null($tab_recuperation_entrees['idStructureEntree'])){
			$touffe['entrees'][$tab_recuperation_entrees['idEntree']]['structure']['id'] = $tab_recuperation_entrees['idStructureEntree'];
			$touffe['entrees'][$tab_recuperation_entrees['idEntree']]['structure']['nom'] = $tab_recuperation_entrees['structureEntree'];
		}
	
	}
	
	mysql_free_result($result_recuperation_entrees);
	
	// récupération des sorties de la touffe
	$query_recuperation_sorties = "SELECT so.CODESORTIE AS idSortie, so.DATESORTIE AS dateSortie, so.NUMSORTIE AS numSortie, td.NOMTYPEDISPARITION AS disparition, prs.CODEPRETSORTANT AS idPretSortie, stprs.NOMSTRUCTURE AS structurePretSortie, retpre.CODEPRETENTRANT AS idPretRetourEntree, stretpre.NOMSTRUCTURE AS structurePretRetourEntree, cme.CODECOMMANDEEXTERNE AS idCommandeSortie, stcme.NOMSTRUCTURE AS structureCommandeSortie, pes.CODEPERSONNE AS idPersonneSortie, pes.NOMPERSONNE AS nomPersonneSortie, pes.PRENOMPERSONNE AS prenomPersonneSortie, sts.CODESTRUCTURE AS idStructureSortie, sts.NOMSTRUCTURE AS structureSortie ";
	$query_recuperation_sorties .= "FROM sortie so ";
	$query_recuperation_sorties .= "LEFT JOIN type_disparition td ON td.CODETYPEDISPARITION = so.CODETYPEDISPARITION ";
	$query_recuperation_sorties .= "LEFT JOIN pret_sortant prs ON prs.CODEPRETSORTANT = so.CODEPRETSORTANT ";
	$query_recuperation_sorties .= "LEFT JOIN structure stprs ON stprs.CODESTRUCTURE = prs.CODESTRUCTURE ";
	$query_recuperation_sorties .= "LEFT JOIN pret_entrant retpre ON retpre.CODEPRETENTRANT = so.CODEPRETENTRANT ";
	$query_recuperation_sorties .= "LEFT JOIN structure stretpre ON retpre.CODESTRUCTURE = stretpre.CODESTRUCTURE ";
	$query_recuperation_sorties .= "LEFT JOIN commande_externe cme ON cme.CODECOMMANDEEXTERNE = so.CODECOMMANDEEXTERNE ";
	$query_recuperation_sorties .= "LEFT JOIN structure stcme ON stcme.CODESTRUCTURE = cme.CODESTRUCTURE ";
	$query_recuperation_sorties .= "LEFT JOIN personne pes ON pes.CODEPERSONNE = so.CODEPERSONNE ";
	$query_recuperation_sorties .= "LEFT JOIN structure sts ON sts.CODESTRUCTURE = so.CODESTRUCTURE ";
	$query_recuperation_sorties .= "WHERE so.CODETOUFFE = ".$_GET['id']." ";
	$query_recuperation_sorties .= "ORDER BY dateSortie DESC ";
	
	$result_recuperation_sorties = mysql_query($query_recuperation_sorties, $connexion) or logError("RECUPERATION SEMIS-".$query_recuperation_sorties."-".mysql_error());
	
	$touffe['sorties'] = array();
	while($tab_recuperation_sorties = mysql_fetch_assoc($result_recuperation_sorties)){
		
		$touffe['sorties'][$tab_recuperation_sorties['idSortie']]['date'] = $tab_recuperation_sorties['dateSortie'];
		$touffe['sorties'][$tab_recuperation_sorties['idSortie']]['numero'] = $tab_recuperation_sorties['numSortie'];
	
		if(!is_null($tab_recuperation_sorties['disparition'])){
			$touffe['sorties'][$tab_recuperation_sorties['idSortie']]['disparition'] = $tab_recuperation_sorties['disparition'];
		}
		if(!is_null($tab_recuperation_sorties['idPretSortie'])){
			$touffe['sorties'][$tab_recuperation_sorties['idSortie']]['pret']['id'] = $tab_recuperation_sorties['idPretSortie'];
			$touffe['sorties'][$tab_recuperation_sorties['idSortie']]['pret']['structure'] = $tab_recuperation_sorties['structurePretSortie'];
		}
		if(!is_null($tab_recuperation_sorties['idPretRetourEntree'])){
			$touffe['sorties'][$tab_recuperation_sorties['idSortie']]['retour']['id'] = $tab_recuperation_sorties['idPretRetourEntree'];
			$touffe['sorties'][$tab_recuperation_sorties['idSortie']]['retour']['structure'] = $tab_recuperation_sorties['structurePretRetourEntree'];
		}
		if(!is_null($tab_recuperation_sorties['idCommandeSortie'])){
			$touffe['sorties'][$tab_recuperation_sorties['idSortie']]['commande']['id'] = $tab_recuperation_sorties['idCommandeSortie'];
			$touffe['sorties'][$tab_recuperation_sorties['idSortie']]['commande']['structure'] = $tab_recuperation_sorties['structureCommandeSortie'];
		}
		if(!is_null($tab_recuperation_sorties['idPersonneSortie'])){
			$touffe['sorties'][$tab_recuperation_sorties['idSortie']]['personne']['id'] = $tab_recuperation_sorties['idPersonneSortie'];
			$touffe['sorties'][$tab_recuperation_sorties['idSortie']]['personne']['nom'] = $tab_recuperation_sorties['nomPersonneSortie'];
			$touffe['sorties'][$tab_recuperation_sorties['idSortie']]['personne']['prenom'] = $tab_recuperation_sorties['prenomPersonneSortie'];
		}
		if(!is_null($tab_recuperation_sorties['idStructureSortie'])){
			$touffe['sorties'][$tab_recuperation_sorties['idSortie']]['structure']['id'] = $tab_recuperation_sorties['idStructureSortie'];
			$touffe['sorties'][$tab_recuperation_sorties['idSortie']]['structure']['nom'] = $tab_recuperation_sorties['structureSortie'];
		}
	
	}
	
	mysql_free_result($result_recuperation_sorties);
	
?>
<h3>Détail d'une touffe</h3>
<table class="fiche" style="width: 100%;">
	<tr>
		<td style="width: 25%" class="etiquette">Taxon:</td>
		<td style="width: 75%"><?php echo "<a href=\"popup.php?p=gestion/taxon_affiche_popup&amp;id=".$touffe['taxon']['id']."\" onclick=\"popup(this.href, 640, 480); return false;\"><b>".htmlentities(capitalise($touffe['taxon']['famille']), ENT_NOQUOTES, "UTF-8")." ".htmlentities(capitalise($touffe['taxon']['genre']), ENT_NOQUOTES, "UTF-8")." ".htmlentities($touffe['taxon']['espece'], ENT_NOQUOTES, "UTF-8")." ".htmlentities($touffe['taxon']['sousespece'], ENT_NOQUOTES, "UTF-8")." ".htmlentities($touffe['taxon']['variete'], ENT_NOQUOTES, "UTF-8")."</b></a>"; ?></td>
	</tr>
	<tr>
		<td class="etiquette">N° entrée:</td>
		<td>
			<?php 
				if(!is_null($touffe['reference'])){
					echo htmlentities($touffe['reference'], ENT_NOQUOTES, "UTF-8");
				}else{
					echo "<i>aucune</i>";
				}
			?>
		</td>
	</tr>
	<tr>
		<td class="etiquette">N° IPEN:</td>
		<td>
			<?php 
				if(!is_null($touffe['ipen'])){
					echo htmlentities($touffe['ipen'], ENT_NOQUOTES, "UTF-8");
				}else{
					echo "<i>inconnu</i>";
				}
			?>
		</td>
	</tr>
	<tr>
		<td class="etiquette">Plantation:</td>
		<td>
			<?php 
				if(!is_null($touffe['plantation'])){
					echo dateFr($touffe['plantation']);
				}else{
					echo "<i>inconnue</i>";
				}
			?>
		</td>
	</tr>
	<tr>
		<td class="etiquette">Type culture:</td>
		<td>
			<?php 
				if(!is_null($touffe['culture'])){
					echo htmlentities(mb_strtolower($touffe['culture']), ENT_NOQUOTES, "UTF-8");
				}else{
					echo "<i>inconnu</i>";
				}
			?>
		</td>
	</tr>
	<tr>
		<td class="etiquette">Nombre pieds:</td>
		<td>
			<?php 
				if(!is_null($touffe['quantite'])){
					echo $touffe['quantite']." pied(s)";
				}else{
					echo "<i>inconnu</i>";
				}
			?>
		</td>
	</tr>
	<tr>
		<td class="etiquette">Vue dernière fois:</td>
		<td>
			<?php 
				if(!is_null($touffe['vue'])){
					echo dateFr($touffe['vue']);
				}else{
					echo "<i>inconnue</i>";
				}
			?>
		</td>
	</tr>
	<tr>
		<th colspan="2">Statut</th>
	</tr>
	<tr>
		<td class="etiquette">Actuellement:</td>
		<td>
			<?php 
				if(count($touffe['entrees']) > count($touffe['sorties'])){
					echo "<span style=\"font-weight: bold; color: #00AA00;\">au jardin</span>";
				}else{
					echo "<span style=\"font-weight: bold; color: #FF0000;\">sorti</span>";
				}
			?>
		</td>
	</tr>
	<tr>
		<td class="etiquette">Emplacement:</td>
		<td>
			<?php 
				if(!is_null($touffe['parcelle'])){
					echo htmlentities($touffe['parcelle'], ENT_NOQUOTES, "UTF-8");
				}else{
					echo "<i>non-indiqué</i>";
				}
			?>
		</td>
	</tr>
	<tr>
		<td class="etiquette">Etiquette:</td>
		<td>
			<?php 
				if(!is_null($touffe['etiquette'])){
					echo "<img src=\"images/oui.png\" alt=\"oui\" title=\"Possède une étiquette\" /> (<i>état: ".htmlentities(mb_strtolower($touffe['etiquette']), ENT_NOQUOTES, "UTF-8")."</i>)";
				}else{
					echo "<img src=\"images/non.png\" alt=\"non\" title=\"Sans étiquette\" />";
				}
			?>
		</td>
	</tr>
	<tr>
		<th colspan="2">Historique</th>
	</tr>
	<tr>
		<td class="etiquette">Entrées:</td>
		<td>
			<ul>
				<?php 
					foreach($touffe['entrees'] as $entree){
						echo "<li>";
						echo "<span class=\"souligne\"><b>".dateFr($entree['date'])."</b>";
						if(!is_null($entree['numero'])){
							echo " (n° ".htmlentities($entree['numero'], ENT_NOQUOTES, "UTF-8").")";
						}
						echo " :</span> ";
						
						if(isset($entree['visite'])){
							echo " récolté à ".htmlentities(capitalise($entree['visite']['commune']), ENT_NOQUOTES, "UTF-8").", le ".dateFr($entree['visite']['date'])." [<a href=\"popup.php?p=gestion/visitedansnature_affiche_popup&amp;id=".$entree['visite']['id']."\" onclick=\"popup(this.href, 680, 500); return false;\">visite</a>]";
						}
						if(isset($entree['divers'])){
							echo " ".htmlentities($entree['divers'], ENT_NOQUOTES, "UTF-8")." (<i>entrée diverse</i>)";
						}
						if(isset($entree['semis'])){
							echo " transplantée d'un <a href=\"popup.php?p=gestion/semis_affiche_popup&amp;id=".$entree['semis']['id']."\" onclick=\"popup(this.href, 640, 480); return false;\">semis";
							if(!is_null($entree['semis']['reference'])){
								echo " (n° ent. ".htmlentities($entree['semis']['reference'], ENT_NOQUOTES, "UTF-8").")";
							}
							echo "</a>";
						}
						if(isset($entree['personne'])){
							echo " donné par <a href=\"popup.php?p=gestion/personne_affiche_popup&amp;id=".$entree['personne']['id']."\" onclick=\"popup(this.href, 350, 400); return false;\">".htmlentities(capitalise($entree['personne']['prenom']), ENT_NOQUOTES, "UTF-8")." ".htmlentities(mb_strtoupper($entree['personne']['nom']), ENT_NOQUOTES, "UTF-8")."</a>";
						}
						if(isset($entree['commande'])){
							echo " commandé à ".htmlentities($entree['commande']['structure'], ENT_NOQUOTES, "UTF-8").", le ".dateFr($entree['commande']['date'])." [<a href=\"popup.php?p=gestion/commandeinterne_affiche_popup&amp;id=".$entree['commande']['id']."\" onclick=\"popup(this.href, 680, 500); return false;\">commande</a>]";
						}
						if(isset($entree['pret'])){
							echo " emprunté à ".htmlentities($entree['pret']['structure'], ENT_NOQUOTES, "UTF-8")." [<a href=\"popup.php?p=gestion/pretentrant_affiche_popup&amp;id=".$entree['pret']['id']."\" onclick=\"popup(this.href, 500, 400); return false;\">prêt</a>]";
						}
						if(isset($entree['retour'])){
							echo " retour du prêt à ".htmlentities($entree['retour']['structure'], ENT_NOQUOTES, "UTF-8")." [<a href=\"popup.php?p=gestion/pretsortant_affiche_popup&amp;id=".$entree['retour']['id']."\" onclick=\"popup(this.href, 500, 400); return false;\">prêt</a>]";
						}
						if(isset($entree['structure'])){
							echo " donné par <a href=\"popup.php?p=gestion/structure_affiche_popup&amp;id=".$entree['structure']['id']."\" onclick=\"popup(this.href, 400, 500); return false;\">".htmlentities($entree['structure']['nom'], ENT_NOQUOTES, "UTF-8")."</a>";
						}
						
						echo "</li>";
					}
					unset($entree);
				?>
			</ul>
		</td>
	</tr>
	<tr>
		<td class="etiquette">Sorties:</td>
		<td>
			<?php
				if(count($touffe['sorties']) > 0){
					echo "<ul>";
					foreach($touffe['sorties'] as $sortie){
						echo "<li>";
						echo "<span class=\"souligne\"><b>".dateFr($sortie['date'])."</b>";
						if(!is_null($sortie['numero'])){
							echo " (n° ".htmlentities($sortie['numero'], ENT_NOQUOTES, "UTF-8").")";
						}
						echo " :</span>";
						
						if(isset($sortie['disparition'])){
							echo " ".htmlentities($sortie['disparition'], ENT_NOQUOTES, "UTF-8")." (<i>disparition</i>)";
						}
						if(isset($sortie['personne'])){
							echo " donné à <a href=\"popup.php?p=gestion/personne_affiche_popup&amp;id=".$sortie['personne']['id']."\" onclick=\"popup(this.href, 350, 400); return false;\">".htmlentities(capitalise($sortie['personne']['prenom']), ENT_NOQUOTES, "UTF-8")." ".htmlentities(mb_strtoupper($sortie['personne']['nom']), ENT_NOQUOTES, "UTF-8")."</a>";
						}
						if(isset($sortie['commande'])){
							echo " envoyé à ".htmlentities($sortie['commande']['structure'], ENT_NOQUOTES, "UTF-8")." [<a href=\"popup.php?p=gestion/commandeexterne_affiche_popup&amp;id=".$sortie['commande']['id']."\" onclick=\"popup(this.href, 680, 500); return false;\">requête</a>]";
						}
						if(isset($sortie['pret'])){
							echo " prêté à ".htmlentities($sortie['pret']['structure'], ENT_NOQUOTES, "UTF-8")." [<a href=\"popup.php?p=gestion/pretsortant_affiche_popup&amp;id=".$sortie['pret']['id']."\" onclick=\"popup(this.href, 500, 400); return false;\">prêt</a>]";
						}
						if(isset($sortie['retour'])){
							echo " retour du prêt de ".htmlentities($sortie['retour']['structure'], ENT_NOQUOTES, "UTF-8")." [<a href=\"popup.php?p=gestion/pretsortant_affiche_popup&amp;id=".$sortie['retour']['id']."\" onclick=\"popup(this.href, 500, 400); return false;\">prêt</a>]";
						}
						if(isset($sortie['structure'])){
							echo " donné à <a href=\"popup.php?p=gestion/structure_affiche_popup&amp;id=".$sortie['structure']['id']."\" onclick=\"popup(this.href, 400, 500); return false;\">".htmlentities($sortie['structure']['nom'], ENT_NOQUOTES, "UTF-8")."</a>";
						}
						
						echo "</li>";
					}
					unset($sortie);
					echo "</ul>";
				}else{
					echo "<i>aucune</i>";
				}
			?>
		</td>
	</tr>
	<tr>
		<th colspan="2">Commentaire</th>
	</tr>
	<tr>
		<td class="texte" colspan="2"><?php echo nl2br(htmlentities($touffe['commentaire'], ENT_NOQUOTES, "UTF-8")); ?></td>
	</tr>
</table>
<?php
//------------------------------------------------------------ Accès refusé à la page

			}else{
				afficherStatut("La touffe n'existe pas", 3); // appel à la fonction afficherStatut() définie dans fonctions.php
			}

		}else{
			afficherStatut("La touffe n'est pas ou mal indiqué", 3); // appel à la fonction afficherStatut() définie dans fonctions.php
		}

	}else{
		if(isset($_SESSION)){
			include("pages/401.htm");
		}
	}

?>